package top.zhangjianyong.tools.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import top.zhangjianyong.tools.service.api.FreeApiService;
import top.zhangjianyong.tools.user.VerifyUser;
import top.zhangjianyong.tools.utils.ApiResponse;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ： zhangjianyong
 * @date ： 2023/3/3 3:28 PM
 */
@VerifyUser(login = false)
@Controller
@RequestMapping("/free")
public class FreeApiController {

    @Autowired
    private FreeApiService freeApiService;


    @GetMapping("/douyin/video")
    public void douyinVideo(HttpServletResponse response) throws Exception {

        freeApiService.douyinVideo(response);
    }

    @PostMapping("/douyin")
    @ResponseBody
    public ApiResponse douyin() throws Exception {
        return freeApiService.douyin();
    }

    @GetMapping("/douyin")
    @ResponseBody
    public ApiResponse douyin(@RequestParam("url") String url, HttpServletResponse response) throws Exception {
        return freeApiService.douyin(url, response);
    }


    @PostMapping("/pic")
    @ResponseBody
    public ApiResponse pic() throws Exception {
        return freeApiService.pic();
    }

    @GetMapping("/pic")
    public ApiResponse pic(@RequestParam("url") String url, HttpServletResponse response) throws IOException {
        return freeApiService.pic(url, response);
    }

    @PostMapping("/hotVideo")
    @ResponseBody
    public ApiResponse hotVideo() {
        return freeApiService.hotVideo();
    }


    @PostMapping("/hotVideo/update")
    @ResponseBody
    public ApiResponse hotVideoUpdate() {
        return freeApiService.hotVideoUpdateAll();
    }

    @PostMapping("/hotVideo/watch/{videoId}/{watchFlag}")
    @ResponseBody
    public ApiResponse watchHotVideo(@PathVariable("videoId") Long videoId, @PathVariable("watchFlag") Integer watchFlag) {
        return freeApiService.watchHotVideo(videoId, watchFlag);
    }

    @PostMapping("/laji/{name}")
    @ResponseBody
    public ApiResponse laji(@PathVariable("name") String name) {
        return freeApiService.laji(name);
    }

    @PostMapping("/laji/his")
    @ResponseBody
    public ApiResponse lajiHis() {
        return freeApiService.lajiHis();
    }
}
